package com.cskaoyan.controller;

import com.cskaoyan.bean.BaseRespVo;
import com.cskaoyan.bean.MarketUser;
import com.cskaoyan.bean.User;
import com.cskaoyan.bean.UserData;
import com.cskaoyan.bean.param.BaseParam;
import com.cskaoyan.exception.ValidationException;
import com.cskaoyan.service.UserService;
import com.cskaoyan.util.ValidationUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
* @author stone
* @date 2022/01/06 16:23
*/
@RestController
public class UserController {

   @Autowired
   UserService userService;

   @RequestMapping("admin/user/list")
   public BaseRespVo userList(String username,String mobile,BaseParam param) {
       UserData userData = userService.query(param, username,mobile);
       return BaseRespVo.ok(userData);
   }

   @GetMapping("admin/user/detail")
   public BaseRespVo<User> GetUserDetailById(Integer id) {
       MarketUser user = userService.GetUserDetailById(id);
       return BaseRespVo.ok(user);
   }

   @PostMapping("admin/user/update")
   public BaseRespVo<Integer> updateMarketUser(@RequestBody @Validated MarketUser user, BindingResult bindingResult) throws ValidationException {
       ValidationUtil.valid(bindingResult);
       Integer data = userService.updateUser(user);
       return BaseRespVo.ok(data);
   }
}
